<?php

namespace App\Http\Middleware;

use Closure;

class AuthUserInfo
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (auth() -> guard('userinfo')->guest()){
            if ($request -> ajax() || $request -> wantsJson())
            {
                return response('Unauthorized.','404');
            }else{
                return redirect() -> guest('userinfo/login');
            }
        }
        return $next($request);
    }
}
